/**
 * Created by AllanXu on 7/25/2016.
 */
define(function (require) {
	var Vue = require('vue'),
        Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities');

	var app = new Vue({
		el: '#auth',
		data: {
			qrcode: '',
            userInfo: ''
		},
		methods:{
            // init: function(){
            //     app.userInfo = JSON.parse(decodeURIComponent(atob(sessionStorage.userInfo)));
            // },
			save: function () {
                if(app.qrcode == ''){
                    alert("请输入邀请码");
                }else{
                    _(Config.SERVICE.AUTH.SAVE, {
                        "id": sessionStorage.id,
                        "xgmember.code": app.qrcode
                    }, function(data) {
                        console.log(data);
                        // sessionStorage.userInfo = btoa(encodeURIComponent(JSON.stringify(data.obj)));
                        if(data.code==200){
                            // app.userInfo.member.code = app.qrcode;
                            // app.userInfo.member.sfrz = 1;
                            // sessionStorage.userInfo = btoa(encodeURIComponent(JSON.stringify(app.userInfo)));
                            
                            utilities.refreshUserInfo(function (data) {
                                console.log(JSON.parse(decodeURIComponent(atob(sessionStorage.userInfo))),233);
                                window.history.back();
                            });
                        }else{
                            alert(data.errmsg);
                        }
                    });
                }
			}
		}
	});
});